import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class CustomTable<T> extends StatelessWidget {
  final List<TableColumn> columns;
  final List<TableData<T>> data;

  const CustomTable({
    Key key,
    @required this.columns,
    @required this.data,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [];

    children.add(Container(
      color: ColorConstant.ffcc,
      height: 90.w,
      child: Row(
        children: columns.map((item) {
          return Expanded(
            child: Container(
              alignment: Alignment.center,
              child: Text(
                item.title,
                style: TextStyleConstant().normal_2_28,
              ),
            ),
          );
        }).toList(),
      ),
    ));

    children.add(Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: data.map((row) {
        return Row(
          children: row.value.map((cell) {
            return Expanded(
              child: Container(
                height: 90.w,
                alignment: Alignment.center,
                child: Text(
                  '$cell',
                  style: TextStyleConstant().normal_1_28,
                ),
              ),
            );
          }).toList(),
        );
      }).toList(),
    ));

    return ShadowRadiusCard(
      child: ClipRRect(
        borderRadius: BorderRadius.circular(
          14.w,
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: children,
        ),
      ),
    );
  }
}

class TableColumn {
  String title;

  TableColumn({
    @required this.title,
  });
}

class TableData<T> {
  List<T> value;

  TableData({@required this.value});
}
